package cn.seocoo.platform.api.controller;

import cn.seocoo.platform.api.util.JSONResult;
import cn.seocoo.platform.common.core.domain.AjaxResult;
import cn.seocoo.platform.common.utils.StringUtils;
import cn.seocoo.platform.freeback.domain.Freeback;
import cn.seocoo.platform.freeback.service.impl.FreebackServiceImpl;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: ApiFreeBackController
 * @description: 反馈
 * @author: wujian
 * @Date: 2019-12-20 11:09
 **/
@Api(value = "反馈")
@RestController
@RequestMapping("/api/freeBack")
public class ApiFreeBackController {
    @Autowired
    private FreebackServiceImpl freebackService;


    /**
     * @return cn.seocoo.platform.common.core.domain.AjaxResult
     * @Author WuJian
     * @Description //保存反馈信息
     * @Date 11:28 2019/12/20
     * @Param [freeback]
     **/
    @PostMapping("/saveFreeBack")
    public JSONResult saveFreeBack(@RequestBody Freeback freeback) {
        try {
            if (StringUtils.isBlank(freeback.getContent())) {
                return JSONResult.errorMsg("请反馈在使用过程中遇到的问题和建议");
            }
            if (freeback.getAppUserId() == null) {
                return JSONResult.errorMsg("反馈的用户不能为空");
            }
            int row = freebackService.insertFreeback(freeback);
            if (row > 0) {
                return JSONResult.ok("反馈成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JSONResult.errorMsg(JSONResult.ERROR_MSG);
    }
}
